//###########################################################################
//# js.tooltip.js
//# author : Yangkun <yangkun7@kornet.net>
//###########################################################################
//# display tooltip instead of alt
//###########################################################################
Tooltip = function(tags){ 
    if (!document.body.getAttribute) return false; 
	this.tooltip = this.createTipbox();
    this.offsetX = this.offsetY = 10; 

	this.ns5 = ((navigator.userAgent.indexOf("Gecko")>-1)) ? true: false;
    
	if (document.getElementsByTagName) 
    { 
		var tag = tags.split(":");
		for (var i=0;i<tag.length;i++)
		{
			this.init(document.getElementsByTagName(tag[i]));
		}
    } 
} 
Tooltip.prototype.createTipbox = function()
{
	var box=document.createElement("div");
	// box ?.. (style)
	box.style.display = "none";
	box.style.position = "absolute";
	box.style.fontFamily = "";
	box.style.fontSize = "9pt";
	box.style.lineHeight = "170%";
	box.style.padding = "3px";
	box.style.borderStyle = "solid";
	box.style.borderWidth = "1px";
	box.style.borderColor = "black";
	box.style.backgroundColor = "white";
	box.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
	box.style.padding = "3px";
	box.style.borderStyle = "solid";

	document.body.appendChild(box);
    return box;
}
Tooltip.prototype.init = function(){ 
    Tooltip.object = this; 
    Tooltip.element = null; 
    for (var i=0, s=arguments[0].length; i<s; i++) 
    { 
        Tooltip.element = arguments[0][i]; 
        if (arguments[0][i].getAttribute("notip") == null && (arguments[0][i].getAttribute("tip") != null || arguments[0][i].getAttribute("alt") != null || arguments[0][i].getAttribute("title") != null))
        { 
			var tmp = arguments[0][i].getAttribute("tip");
			if (tmp == null)
			{
				tmp = arguments[0][i].getAttribute("alt");
				if (tmp != null)
				{
					arguments[0][i].setAttribute("tip", tmp);
					arguments[0][i].removeAttribute("alt");
				}
			}
			if (tmp == null)
			{
				tmp = arguments[0][i].getAttribute("title");
				if (tmp != null)
				{
					arguments[0][i].setAttribute("tip", tmp);
					arguments[0][i].removeAttribute("title");
				}
			}

			if (this.ns5)
			{
				arguments[0][i].onmouseover = function(evt){ 
					Tooltip.object.show(this, evt.pageX, evt.pageY);
				} 
				arguments[0][i].onmousemove = function(evt){
					Tooltip.object.move(evt.pageX, evt.pageY);
				} 
				arguments[0][i].onmouseout = function(){ 
					Tooltip.object.hide(); 
				} 
			}
			else
			{
				arguments[0][i].onmouseover = function(){ 
					Tooltip.object.show(event.srcElement, event.x, event.y); 
				} 
				arguments[0][i].onmousemove = function(){ 
					Tooltip.object.move(event.x, event.y); 
				} 
				arguments[0][i].onmouseout = function(){ 
					Tooltip.object.hide(); 
				} 
			}
        } 
    } 
} 
Tooltip.prototype.show = function(source, x, y) 
{ 
	var t = source.getAttribute("tip");
	
	if (t == null && source.parentElement != null)
	{
		var tmp = source;
		while (tmp != null && tmp.parentElement != null)
		{
			t = tmp.parentElement.getAttribute("tip");
			if (t != null) break;
			tmp = tmp.parentElement;
		}
	}

	if (t != null && t != '')
	{
		this.tooltip.innerHTML = t; 
		this.tooltip.style.display = "inline";
		this.move(x,y); 
	}
} 
Tooltip.prototype.move = function(x, y) 
{ 
	var width = this.tooltip.clientWidth; 
    var height = this.tooltip.clientHeight;
    var cx = document.body.clientWidth; 
    var cy = document.body.clientHeight;
    var sy = document.documentElement.scrollTop;
    var tx = x + this.offsetX; 
    var ty = y + this.offsetY + sy;
    if (tx + width + 1 >= cx) tx -= (tx + width - cx+2); 
    if (ty + height >= cy + sy) ty -= (ty + height - (cy+sy)); 
    this.tooltip.style.left = tx; 
    this.tooltip.style.top = ty; 
} 
Tooltip.prototype.hide = function() 
{ 
    this.tooltip.style.display = "none"; 
}